import yolov5
import time
model = yolov5.load('last.pt')
print("statr")

while(1):
    time.sleep(0.2)
    img = '../res/img.jpg'
    

    results = model(img)
    predictions = results.pred[0]
    boxes = predictions[:,:4]

    fo = open("../res/x.txt","w")
    si=boxes.size()[0]
    if(si>0):
        x1 = boxes[0][0].numpy()
        y1 = boxes[0][1].numpy()
        x2 = boxes[0][2].numpy()
        y2 = boxes[0][3].numpy()
    

        s = str(int(x1))+"\n"+str(int(y1))+"\n"+str(int(x2))+"\n"+str(int(y2))
        ss = "x1:"+str(int(x1))+"\ny1:"+str(int(y1))+"\nx2:"+str(int(x2))+"\ny2:"+str(int(y2))+"\n"
        print(ss)
        fo.write(s)
        fo.close()
    else:
        print("void")
        fo.close()
